<template>
	<view>
		<view style="margin-top: 20rpx;">

		</view>
		<navbar title="私教课堂定制"   :right-icon="iconimg" @clickLeft="clickfun" @clickRight="getotherdata" left-icon="left" >
		</navbar>
		
		<!-- 轮播图 -->
		<view class="" v-show="scene == 1">
			<view class="content">
				<swiper class="swiper-box" :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval"
					:duration="duration">
					<swiper-item v-for="(item, index) in theswiper" :key="index">
						<view :class="item.colorClass" class="swiper-item">
							<!-- #ifdef APP-PLUS -->
							<image class="image" :src="item.urlimg" mode="aspectFill" />
							<!-- #endif -->
							<img v-lazy="item.urlimg" class="image" >
						</view>
						<view class="itemtitle">
							{{item.title}}
						</view>
						<view class="itemcontent">
							{{item.content}}
						</view>
						<view class="butsubmit" @click="vipshow">
							vip私人教定制
						</view>
					</swiper-item>
		
				</swiper>
			</view>
		</view>
		<view style="display: flex;justify-content: center;" v-show="scene == 2">
			<image style="width: 300rpx;height: 300rpx;" src="/static/img/sanbing.jpg" mode="widthFix"></image>
		</view>
		<view class="" v-show="scene==1">
			<view class="" v-for="(item,index) in datalist" :key="index">
				<view class="theline">
					<view class="line-right" @click="swipisshow(item)">
						<view style="font-weight: 600;font-size: 36rpx;">
							{{item.newarr[0].class}}
						</view>
						<!-- 展开icon -->
						<view class="" v-if="item.isshowdetail">
							<image style="margin-left: 10rpx; width: 30rpx;height: 30rpx;"
								src="../../static/tabBar/up_1.png" mode=""></image>
						</view>
						<view class="" v-else>
							<image style="margin-left: 10rpx; width: 30rpx;height: 30rpx;"
								src="../../static/tabBar/down_1.png" mode=""></image>
						</view>
					</view>

				</view>
				<!-- 收起详情: -->
				<template>
					<view v-show="item.isshowdetail">
						<view class="packdetail">
							<view class="packdetail_left" v-for="(it,ind) in item.newarr" :key="ind"
								@click="govip(it.subject,it.id)">
								
								{{it.subject}}
							</view>
						</view>
						<myline></myline>
					</view>
				</template>
			</view>
		</view>
		<view class="" v-show="scene==2">
			<view class="" v-for="(item,index) in datalist2" :key="index">
				<view class="theline">
					<view class="line-right" @click="swipisshow(item)">
						<view style="font-weight: 600;font-size: 36rpx;">
							{{item.newarr[0].class}}
						</view>
						<!-- 展开icon -->
						<view class="" v-if="item.isshowdetail">
							<image style="margin-left: 10rpx; width: 30rpx;height: 30rpx;"
								src="../../static/tabBar/up_1.png" mode=""></image>
						</view>
						<view class="" v-else>
							<image style="margin-left: 10rpx; width: 30rpx;height: 30rpx;"
								src="../../static/tabBar/down_1.png" mode=""></image>
						</view>
					</view>
		
				</view>
				<!-- 收起详情: -->
				<template>
					<view v-show="item.isshowdetail">
						<view class="packdetail">
							<view class="packdetail_left" v-for="(it,ind) in item.newarr" :key="ind"
								@click="govip(it.subject,it.id)">
								
								{{it.subject}}
							</view>
						</view>
						<myline></myline>
					</view>
				</template>
			</view>
		</view>
		

		<view v-if="isShow" class="reserva-detal" @touchmove.stop.prevent="">
			<!-- 阴影框 -->
			<view class="pop-mask" @tap="hidePop()">
			</view>
			<view class="pop-box" :animation="animationData">
				<view class="pop-btitle">
					定制教师具体要求
				</view>
				<mline></mline>
				<textarea v-model="situation" class="sit-text" name="" id="" cols="30" rows="10" ></textarea>
				<view class="pop-sub" @tap="gopay">
					确定
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import myline from '@/components/common/Lines.vue'
	import $http from '@/common/api/request.js'
	import navbar from "@/components/uni/uni-nav-bar/uni-nav-bar.vue"
	import mline from '@/components/common/Lines.vue'
	export default {
		data() {
			return {
				indicatorDots: true,
				autoplay: true,
				interval: 2000, //切换的间隔时间
				duration: 300, //滑动动画时长
				
				isshowdetail: true,
				datalist: [],
				datalist2: [],
				theswiper: [],
				viplist: [{
						id: 1,
						title: "测评报告"
					},
					{
						id: 2,
						title: "课程大纲"
					},
					{
						id: 3,
						title: "活页教材"
					},
					{
						id: 4,
						title: "资料手册"
					},
					{
						id: 5,
						title: "学情报告"
					}
				],
				ismember: 0,
				timer:null,
				callbackdatalist:[],
				iconimg:"tune",
				scene:2,
				isShow: false,
				animationData: {}, //动画过渡
				situation: "", //学生学习情况
				subject:"",
				itid:0,
				rules: {
					situation: {
						rule: /.{5,200}$/,
						msg: "学员情况尚未填写,请填写5~200字内容"
					}
				}
			};
		},
		components: {
			myline,
			navbar,
			mline
		},
		methods: {
			//正则校验
			validate(key) {
				let bool = true;
				if (!this.rules[key].rule.test(this[key])) {
					uni.showToast({
						title: this.rules[key].msg,
						icon: "none"
					})
					bool = false;
					return bool;
				}
				return bool;
			},
			//关闭阴影框
			hidePop() {
				var animation = uni.createAnimation({
					duration: 200,
				})
				animation.translateY(0).step()
				this.animationData = animation.export()
				setTimeout(() => {
					animation.translateY(600).step()
					this.isShow = false;
					this.this.situation=''
				}, 200)
			
			},
			//阴影框的确认按钮:
			gopay(){
				if(this.validate('situation')){
					
					uni.navigateTo({
						url:`/pages/vipcourseteacherlist/index?senddata=${JSON.stringify({subject:this.subject,scene:this.scene,id:this.itid,situation:this.situation})}`
					})
					this.situation=''
				}else{
					//每天输入框:
					return
				}
				
			},
			//获取是否含有会员
			getismember() {
				$http.request({
					url: "/getismember",
					method: "POST",
					header: {
						token: true
					},
				}).then((res) => {
					
					if (res.code == 200 ) {
						
						this.ismember = res.message.state;
					}

				}).catch(() => {
					uni.showToast({
						title: "获取会员失败..",
						icon: "error",
						mask: true,
						duration: 2000
					})
				})
				
			},
			clickfun() {
				uni.navigateTo({
					url:'/pages/taplist/taplist'
				})
			},
			goVIPpage() {
				uni.navigateTo({
					url: "/pages/taplist/taplist"
				})
			},
			isselect(index) {
				this.selectindex = index;
			},
			swipisshow(item) {
				item.isshowdetail = !item.isshowdetail;
			},
			//开启定时器
			startTimer() {
			      // 设置定时器，每隔一秒执行一次
			      this.timer = setInterval(() => {
					  this.stopTimer()
			        // 这里写定时执行的代码
			        uni.navigateTo({
			        	url:'/pages/member/member'
			        })
			      }, 1000);
			},
			//结束定时器
			stopTimer() {
			      // 停止定时器
			      clearInterval(this.timer);
			      this.timer = null;
			    },
			govip(it,itid) {
				//判断是否为会员:
				if(this.ismember){
					//是:跳转到教师排名列表
					//需要进一步填写个人的具体情况:
					this.isShow = true;
					this.subject = it;
					this.itid = itid
					
				}else{//不是得去开通会员,跳转会员
					uni.showToast({
						title:"未开通会员",
						icon:"none"
					})
					this.startTimer()
				}
				
			},
			//获取基本数据
			getdatalist() {
				$http.request({
					url: "/getvipketang",
				}).then((res) => {
					this.callbackdatalist = res.map(item => {
						item.isshowdetail = false
						return item
					})
					this.datalist = this.callbackdatalist.slice(0, 6)
					this.datalist2 = this.callbackdatalist.slice(6, this.callbackdatalist.length);
				})
			},
			getotherdata(){
				if(this.scene == 1){
					
					this.iconimg = "tune";
					this.scene = 2;
				}else{
					this.iconimg = "medal";
					this.scene = 1;
				}
				
				
			},
			//获取轮播图数据
			getvipswiper() {
				$http.request({
					url: "/getvipswiper",
				}).then((res) => {
					this.theswiper = res.map(item => {
						item.urlimg = `https://zyc618.mynatapp.cc${item.img}`
						return item
					})


				}).catch(() => {

				})
			},
			vipshow() {
				if(this.ismember){
					uni.showToast({
						title: "私人家教,让你的孩子更进一大步"
					})
					this.autoplay = false
				}else{
					uni.showToast({
						title:"未开通会员",
						icon:"none"
					})
					this.startTimer()
				}
				
			}
		},
		onLoad() {
			this.getdatalist();
			this.getvipswiper();
			this.getismember();
		},
		beforeDestroy() {
			
		}
	}
</script>

<style lang="scss">
	.viplistselect {

		position: relative;
	}

	.linemy {
		position: absolute;
		z-index: -1;
		top: 30rpx;
		left: 0;
		width: 125rpx;
		border-bottom: 12rpx solid #e6463e;
	}

	.packdetail {
		display: flex;
		padding: 10rpx 30rpx;
		
		flex-wrap: wrap;
		
		align-self: center;

		.packdetail_left {
			width: 28%;
			border: 1rpx solid #b52dcd;
			border-radius: 10rpx;
			padding: 10rpx 3rpx;
			
			margin: 10rpx;
			display: -webkit-box;
			-webkit-box-orient: vertical;
			-webkit-line-clamp: 1;
			overflow: hidden;
			text-overflow: ellipsis;
			text-align: center;
		}

		.packdetail_right {
			width: 70%;
			margin-left: 10rpx;
		}

	}

	.theline {
		margin-top: 30rpx;
		padding: 10rpx 20rpx;
		height: 40rpx;

		.line-right {
			font-size: 32rpx;
			display: flex;
			justify-content: space-between;
			align-self: center;

		}
	}

	.page {
		width: 100%;
		height: 100%;
	}

	.content {
		/* text-align: center; */
		height: 800rpx;

	}

	.swiper-box {

		height: 800rpx;
	}

	.swiper-item {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		align-items: center;

	}

	.image {
		width: 450rpx;
		height: 450rpx;
		border-radius: 300rpx;
	}

	.itemtitle {
		display: flex;
		justify-content: center;
		padding: 10rpx;
		font-weight: 600;
		font-size: 36rpx;
	}

	.itemcontent {
		display: flex;
		justify-content: center;
		padding: 20rpx;
		font-size: 30rpx;
	}

	.butsubmit {
		display: flex;
		justify-content: center;
		padding: 30rpx;
		border: 1rpx solid #fee8dd;
		border-radius: 20rpx;
	}
	.reserva-detal {
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		z-index: 999;
	
		.pop-mask {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
			background-color: rgba(0, 0, 0, .6);
		}
	
		.pop-box {
			position: absolute;
			left: 0;
			bottom: 0;
			width: 100%;
			background-color: #ffffff;
			border-radius: 30rpx;
	
			.pop-btitle {
				text-align: center;
			}
	
			.pop-top {
				display: flex;
				padding: 20rpx 20rpx;
	
				.pop-img {
					width: 40%;
					height: 360rpx;
				}
	
				.pop-img-right {
					width: 50%;
					flex-wrap: wrap;
					align-items: flex-end;
					padding: 5rpx 20rpx;
					margin-top: 175rpx;
				}
			}
	
			.pop-line {
				font-size: 28rpx;
	
				.line-top {}
	
				.line-moy {
					padding: 10rpx;
				}
	
			}
	
			.pop-sub {
				z-index: 9999;
				line-height: 80rpx;
				background-color: #498DFB;
				color: #FFFFFF;
				text-align: center;
			}
		}
	}
</style>